package com.lcredu.utils;

import org.apache.commons.beanutils.BeanUtils;

import java.util.Map;

/**
 * @author 黎长容
 * @date 2025-07-06 17:05
 */
public class DataUtils {

    //封装拷贝的方法
    public static <T> T getBeanFromMap(Map value, T bean) {
        try {
            BeanUtils.populate(bean, value);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return bean;
    }

    //将字符串转为整数,否则返回默认值
    public static int parserInt(String val, int num) {

        try {
            return Integer.parseInt(val);
        } catch (NumberFormatException e) {
//            System.out.println("格式转换错误...");
        }

        //转换错误可以直接返回默认值
        return num;
    }
}
